<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../css/reset.css">
    <style>
        .box {
            width: 200px;
            height: 200px;
            background-color: #6ff;
            margin: 50px auto;
            overflow: hidden;
        }

        .box .sub {
            width: 80px;
            height: 80px;
            background-color: grey;
            margin: 60px;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="sub"></div>
    </div>
</body>
<script>
    // onmouseover和onmouseout的问题
    // 给父元素绑定onmouseover和onmouseout,滑过子(代)元素也会触发父元素绑定的事件(先触发划出在触发划入)  => 重复触发

    // 解决方法
    // 使用onmouseenter和onmouseleave替换 onmouseover和onmouseout

    // var box = document.querySelector(".box");
    // box.onmouseover = function () {
    //     console.log("鼠标划入");
    // }
    // box.onmouseout = function () {
    //     console.log("鼠标划出");
    // }


    var box = document.querySelector(".box");
    box.onmouseenter = function () {
        console.log("鼠标划入");
    }
    box.onmouseleave = function () {
        console.log("鼠标划出");
    }


</script>

</html>